<?php
use common\service\StaticService;
use backend\assets\AdminAsset;
use common\service\GlobalUrlService;
$this->title = '添加分类';

StaticService::includeAppJsStatic(GlobalUrlService::buildStaticUrl('/backend/qiniu.min.js'),AdminAsset::class);
StaticService::includeAppJsStatic(GlobalUrlService::buildStaticUrl('/backend/tree/add-tree.js'),AdminAsset::class);
$nbsp = [
    1 =>'&nbsp;',
    2 =>'&nbsp;&nbsp;&nbsp;&nbsp;',
    3 =>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
    4 =>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
];
?>

<div class="layui-card">
    <div class="layui-card-header">添加分类</div>
    <div class="layui-card-body">
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-inline">
                <input type="text" class="layui-input" name="tree_name">
            </div>
        </div>
        <div class="layui-form-item layui-form">
            <label class="layui-form-label">父级</label>
            <div class="layui-inline">
                <select class="select">
                    <option value="0">└顶级菜单</option>
                    <?php foreach ($trees as $val):?>
                        <option value="<?=$val['id']?>"><?php echo $nbsp[$val['level']] ?>└<?=$val['tree_name']?></option>
                    <?php endforeach;?>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">上传图片</label>
            <div class="layui-inline">
                <input type="file" id="pic" class="classify" style="display:none;">
                <label class="layui-btn layui-btn-primary" for="pic">选择图片</label>
                <div class="p40">
                    <label for="pic">
                        <img src="" class="pic">
                        <img src="<?= GlobalUrlService::buildStaticUrl('img/add-pic.png')?>" class="default">
                    </label>
                    <input type="hidden" class="hidden-pic" >
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <a class="layui-btn save-classify">保存</a> 
            <a class="layui-btn layui-btn-primary"  href="<?= GlobalUrlService::buildAdminUrl('tree/index')?>">取消</a>
        </div>
    </div>
</div>

<style>
    .p40{padding-top:45px;}
    .pic{width:170px;height:170px;display:none;}
    .default{width:170px;height:170px;}
    .label-pic{text-align:center;border:1px solid #ccc;width:80px;cursor:pointer;}
</style>